var a = require("../../components/wux"), t = getApp();

Page({
    data: {
        provinceIndex: 0,
        provinces: [],
        roleIndex: 0,
        roleNames: [],
        roleValues: [],
        pageNo: 1,
        total: -1,
        listDatas: [],
        sendOrderId: 0
    },
    loadData: function(a) {
        var e = this, o = e.data.pageNo;
        if (a) o = 1; else if (e.data.total == e.data.listDatas.length) return;
        t.network.post({
            url: t.url.listSendOrder,
            params: {
                pageNo: o,
                province: e.data.provinces[e.data.provinceIndex],
                role: e.data.roleValues[e.data.roleIndex]
            },
            before: function() {
                wx.showNavigationBarLoading();
            },
            success: function(n) {
                if (1 == n.data.result) {
                    var i = [];
                    a || (i = e.data.listDatas), i = i.concat(n.data.data.sendOrders), o += 1, e.setData({
                        total: n.data.data.total,
                        listDatas: i,
                        pageNo: o
                    });
                } else t.util.showToast(n.data.message);
            },
            fail: function() {
                t.util.showToast("获取数据失败");
            },
            complete: function() {
                wx.hideNavigationBarLoading(), wx.stopPullDownRefresh();
            }
        });
    },
    changeProvince: function(a) {
        this.data.provinceIndex != a.detail.value && (this.setData({
            provinceIndex: a.detail.value,
            pageNo: 1,
            total: -1,
            listDatas: []
        }), this.loadData(!0));
    },
    changeRole: function(a) {
        this.data.roleIndex != a.detail.value && (this.setData({
            roleIndex: a.detail.value,
            pageNo: 1,
            total: -1,
            listDatas: []
        }), this.loadData(!0));
    },
    bindQiangdan: function(e) {
        if (t.util.isLoginPage()) {
            var o = e.currentTarget.dataset.sendorderid, n = this;
            a.$wuxDialog.prompt({
                title: "输入报价",
                content: " ",
                fieldtype: "number",
                password: 0,
                defaultText: "",
                placeholder: "请输入报价",
                maxlength: 6,
                onConfirm: function(a) {
                    var t = n.data.$wux.dialog.prompt.response;
                    n.qiangdan(o, t);
                }
            });
        }
    },
    qiangdan: function(a, e) {
        t.network.post({
            url: t.url.addSendOrderUser,
            params: {
                sendOrderId: a,
                price: e
            },
            before: function() {
                wx.showLoading({
                    title: "正在抢单"
                });
            },
            success: function(a) {
                a.data.result, t.util.showToast(a.data.message);
            },
            fail: function() {
                t.util.showToast("抢单失败");
            },
            complete: function() {
                wx.hideLoading();
            }
        });
    },
    onLoad: function(a) {
        this.setData({
            provinces: t.globalData.provinces,
            roleNames: t.globalData.roleNames,
            roleValues: t.globalData.roleValues
        });
    },
    onReady: function() {
        this.loadData(!0);
    },
    onShow: function() {
        t.globalData.currentTab = "/pages/sendOrder/sendOrder", wx.showTabBar({});
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {
        wx.stopPullDownRefresh(), this.loadData(!0);
    },
    onReachBottom: function() {
        t.log("onReachBottom"), this.loadData(!1);
    }
});